/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.univali.programacao.carraid;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

public class ContadorDeFPS extends GameObject {

    private int quadroAtual = 0;
    
    private int fps = 0;
    
    private AcumuladorDeTempo acumulador = new AcumuladorDeTempo(1000);
    
    @Override
    public void update(long tempoDoFrame) {
        quadroAtual++;
        acumulador.update(tempoDoFrame);
        if( acumulador.expirou() ) {
            acumulador.reseta();
            fps = quadroAtual;
            quadroAtual = 0;
            
        }
    }

    /**
     * @return the fps
     */
    public int getFps() {
        return fps;
    }

    @Override
    public void draw(Graphics2D g) {
        g.setTransform(new AffineTransform());
        
        g.setColor(Color.red);
        g.drawString("FPS: "+ getFps(), (int)getX(), (int)getY());
    }
    
}